import 'dart:io';

import 'package:word_game/battle/monster_manager.dart';
import 'package:word_game/engine/core.dart';
import 'package:word_game/engine/eventable_manager.dart';
import 'package:word_game/engine/npc_manager.dart';
import 'package:word_game/engine/scene_manager.dart';
import 'package:word_game/roar_skill.dart';
import 'package:word_game/task/task_core.dart';
import 'package:word_game/task/task_manager.dart';

import 'rpg_hero.dart';
import 'rpg_hero_factory.dart';
import 'wmzk_skill.dart';
import 'yjm_skill.dart';
import 'mked_skill.dart';
import 'mhsn_skill.dart';

import 'cmdline_displayer.dart';

void main(List<String> arguments) async {
  Engine.instance.initData = () {
    HeroFactory.addFactoryForType(HeroFactory(), 'hero');
    HeroFactory.addFactoryForType(TaskableHeroFactory(), 'taskable_hero');
    HeroFactory.addFactoryForType(RPGHeroFactory(), 'rpg_hero');
    NPCFactory.addFactoryForType(NPCFactory(), 'npc');
    NPCFactory.addFactoryForType(TaskableNPCFactory(), 'taskable_npc');
    
    EventableManager.instance.appendObjectsFromYAML('./game_data.yaml');
    MaterialManager.instance.appendMeterialsFromYAML('./game_data.yaml');
    TaskManager.instance.appendTasksFromYAML('./game_data.yaml');
    NPCManager.instance.appendObjectsFromYAML('./game_data.yaml');
    MonsterManager.instance.appendObjectsFromYAML('./game_data.yaml');
    SceneManager.instance.appendObjectsFromYAML('./game_data.yaml');

    Scene rootScene = SceneManager.instance.objectWithCode('birthplace');
    World.instance.root = rootScene;
    RPGHero hero = HeroFactory.newHeroWithType('rpg_hero', {'name':'龙傲天'});
    hero.skills.add(RoarSkill());
    hero.skills.add(YJMSkill());
    hero.skills.add(MKEDSkill());
    hero.skills.add(MHSNSkill());
    hero.skills.add(WMZKSkill());
    World.instance.hero = hero;
    Engine.instance.displayer.displayString(World.instance.display());
  };
  Engine.instance.displayer = CMDLineDisplayer();
  Engine.instance.init();
  while (true) {
    Engine.instance.waitForInput();
    String input = stdin.readLineSync();
    await Engine.instance.handleInput(input);
  }
}
